<%extends"admin/base.html"%><%block content%>
<link rel="stylesheet" type="text/css" href="<< url_for('static', filename='css/xterm.css') >>">
<script src="<< url_for('static', filename='js/xterm.js') >>" charset="utf-8"></script>
<div class="layui-card">
    <div class="layui-card-header">系统设置</div>
    <div class="layui-card-body">
        <div class="layui-tab layui-tab-brief" lay-filter="system_tab">
          <ul class="layui-tab-title">
            <li class="layui-this">网站设置</li>
            <li>邮箱设置</li>
            <li>Celery设置</li>
            <li>缓存设置</li>
            <li>服务设置</li>
          </ul>
          <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form" wid100 lay-filter="">
                      <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">首页标题</label>
                        <div class="layui-input-block">
                          <input name="common_title" class="layui-input" value="<< common_title >>">
                        </div>
                      </div>
                      <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">META关键词</label>
                        <div class="layui-input-block">
                          <textarea name="common_keywords" class="layui-textarea" placeholder="多个关键词用英文状态 , 号分割"><< common_keywords >></textarea>
                        </div>
                      </div>
                      <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">META描述</label>
                        <div class="layui-input-block">
                          <textarea name="common_description" class="layui-textarea"><< common_description >></textarea>
                        </div>
                      </div>
                      <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">版权信息</label>
                        <div class="layui-input-block">
                          <input name="common_copyright" class="layui-input" value="<< common_copyright >>">
                        </div>
                      </div>
                      <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">版权信息2</label>
                        <div class="layui-input-block">
                          <input name="common_icp" class="layui-input" value="<< common_icp >>">
                        </div>
                      </div>
                       <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">Logo</label>
                        <div class="layui-input-inline">
                      <input name="common_logo" lay-verify="required" id="common_logo" placeholder="图片地址" value="<< common_logo >>" class="layui-input">
                    </div>
                    <div class="layui-input-inline layui-btn-container" style="width: auto;">
                      <button type="button" class="layui-btn layui-btn-primary" id="photo_Upload">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                      </button>
                      <button class="layui-btn layui-btn-primary" id="avartatPreview">查看图片</button >
                    </div>
                      </div>
                      <div class="layui-form-item">
                        <div class="layui-input-block">
                          <button class="layui-btn" lay-submit lay-filter="set_website">确认保存</button>
                        </div>
                      </div>
                    </div>
                </div>
                <div class="layui-tab-item">
                    <div class="layui-form" wid100 lay-filter="">
                        <% for email_key in email_dict %>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label"><< email_key | replace('mail_','') >></label>
                            <div class="layui-input-block">
                                <input name="<< email_key >>" class="layui-input" value="<< email_dict[email_key] >>">
                            </div>
                        </div>
                        <% endfor %>
                        <div class="layui-form-item">
                        <div class="layui-input-block">
                          <button class="layui-btn" lay-submit lay-filter="set_config">确认保存</button>
                        </div>
                      </div>
                    </div>
                </div>
                <div class="layui-tab-item">
                    <div class="layui-form" wid120 lay-filter="">
                        <% for celery_key in celery_dict %>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label"><< celery_key | replace('celery_','') | replace('celeryd_','') >></label>
                            <div class="layui-input-block">
                                <input name="<< celery_key >>" class="layui-input" value="<< celery_dict[celery_key] >>">
                            </div>
                        </div>
                        <% endfor %>
                         <div class="layui-form-item">
                           <label class="layui-form-label">终端查询</label>
                            <div class="layui-input-block">
                                <div id="terminal" style="height: 150px;"></div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                              <button class="layui-btn" lay-submit lay-filter="set_config">确认保存</button>
                              <button class="layui-btn layui-btn-danger restart_celery">重启Celery</button>
                            </div>
                        </div>

                    </div>
                </div>
                <div class="layui-tab-item">
                    <div class="layui-form" wid100 lay-filter="">
                        <% for cache_key in cache_dict %>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label"><< cache_key | replace('cache_','') >></label>
                            <div class="layui-input-block">
                                <input name="<< cache_key >>" class="layui-input" value="<< cache_dict[cache_key] >>">
                            </div>
                        </div>
                        <% endfor %>
                        <div class="layui-form-item">
                        <div class="layui-input-block">
                          <button class="layui-btn" lay-submit lay-filter="set_config">确认保存</button>
                        </div>
                      </div>
                    </div>
                </div>
                <div class="layui-tab-item">
                    <table class="layui-table" id="pid_status" layer-filter="pid_status"></table>
                    <div class="layui-btn-container" style="padding-top: 10px">
                        <button class="layui-btn layui-btn-danger restart_sever">重启服务</button>
                  </div>
                </div>
          </div>
      </div>
</div>
    <script type="text/html" id="stateTpl">
        <span class="layui-badge {{ d.State == 'CLOSED' ? '' : (d.State == 'ESTABLISHED'?'layui-btn-warm':'layui-bg-blue') }}">{{ d.State }}</span>
    </script>
<%endblock%>
<%block script%>
    form.on("submit(set_website)", function(t) {
        var filed=t.field;
        filed.type='system';
        $.ajax({
            url:'<< url_for("admin.SystemInfo") >>',
            type:'post',
            data:filed,
            dataType:'json',
            success:function(res){
                if(res.status==1){
                  layer.msg('修改成功')
                }
                else{
                  layer.msg(res.msg);
                }
            }
        })
    });
    var r = $("#common_logo");
    form.on("submit(set_config)", function(t) {
        var filed=t.field;
        filed.type='config';
        $.ajax({
            url:'<< url_for("admin.SystemInfo") >>',
            type:'post',
            data:filed,
            dataType:'json',
            success:function(res){
                if(res.status==1){
                  layer.msg('修改成功')
                }
                else{
                  layer.msg(res.msg);
                }
            }
        })
    });
    //获取celery状态
        function get_celery_info(){
        $('#terminal').html('');
         $.ajax({
            url: "<< url_for('admin.SystemInfo') >>",
            data:{type:'celery'},
            type:'post',
            dataType:'json',
            success:function(res){
                var term = new Terminal({rows:9,convertEol: true});
                term.open(document.getElementById('terminal'));
                term.write(res.data)
            }
          });
    }
     $('.restart_celery').click(function(t) {
        $.ajax({
            url:'<< url_for("admin.RestartCelery") >>',
            dataType:'json',
            success:function(res){
                 if(res.status==0)
                 {
                    notice.info('重启成功');
                    setTimeout(function(){get_celery_info()},2000);
                 }
                 else
                {
                    notice.warning(res.msg);
                }
             }
            ,error:function () {
                   notice.error('网络异常')
             }
        });
    });
    table.render({
        elem: "#pid_status",
        url: "<< url_for('admin.SystemInfo') >>",
        text: {
            none: '暂无相关数据', //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            error:'对不起，加载出现异常！'
        },
        where:{'type':'pid'},
        method:'post',
        cols: [[{field: "Proto", title: "协议"},{field: "Recv-Q", title: "接收队列"},{field: "Send-Q", title: "发送队列"},{field: "Local_Address", title: "本地IP地址"},{field: "Foreign_Address", title: "外部IP地址"},{field: "State", title: "状态", templet: "#stateTpl"},{field: "PID/Program name", title: "PID/进程名"}]],
        page: false
    })
    element.on('tab(system_tab)', function(data){
      if(data.index==2){
         get_celery_info();
        }
    });
    $("#avartatPreview").click(function(){
        var i = r.val();
        layer.photos({
            photos: {
                title: "查看头像",
                data: [{
                    src: i
                }]
            },
            shade: .01,
            closeBtn: 1,
            anim: 5
        });
    });
    upload.render({
        url: "<< url_for('main.upload') >>?action=uploadimage",
        elem: "#photo_Upload",
        before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
        layer.load(); //上传loading
      }
      ,acceptMime: 'image/*'
      ,accept:'images'
      ,progress: function(n, elem){
        var percent = n + '%';//获取进度百分比
        element.progress('demo', percent); //可配合 layui 进度条元素使用
      }
       ,done: function(t) {
            1 == t.status ? r.val(t.data.src) : layui.msg(t.msg, {
                icon: 5
            })
            layer.closeAll('loading'); //关闭loading
        }
        ,error: function(index, upload){
        layer.msg('网络异常');
        layer.closeAll('loading'); //关闭loading
      }
    });
    $('.layui-nav-child dd').removeClass('layui-this');
    $('#view_admin_system').addClass('layui-this');
    $('.layui-nav-tree li').removeClass('layui-nav-itemed');
    $('#admin_system_nav').addClass('layui-nav-itemed');
<% endblock %>